home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / man / cmds.fmt / sed.man < prev    next >
Encoding:
Text File  |  1989-06-01  |  7.8 KB  |  265 lines

  1.  
  2.  
  3.  
  4. SED                       User Commands                       SED
  5.  
  6.  
  7.  
  8. NNAAMMEE
  9.      sed - stream editor
  10.  
  11. SSYYNNOOPPSSIISS
  12.      sseedd [ --nn ] [ --ee script ] [ --ff sfile ] [ file ] ...
  13.  
  14. DDEESSCCRRIIPPTTIIOONN
  15.      _S_e_d copies the named _f_i_l_e_s (standard input default) to the
  16.      standard output, edited according to a script of commands.
  17.      The --ff option causes the script to be taken from file _s_f_i_l_e;
  18.      these options accumulate.  If there is just one --ee option
  19.      and no --ff's, the flag --ee may be omitted.  The --nn option
  20.      suppresses the default output.
  21.  
  22.      A script consists of editing commands, one per line, of the
  23.      following form:
  24.  
  25.           [address [, address] ] function [arguments]
  26.  
  27.      In normal operation _s_e_d cyclically copies a line of input
  28.      into a _p_a_t_t_e_r_n _s_p_a_c_e (unless there is something left after a
  29.      `D' command), applies in sequence all commands whose
  30.      _a_d_d_r_e_s_s_e_s select that pattern space, and at the end of the
  31.      script copies the pattern space to the standard output
  32.      (except under --nn) and deletes the pattern space.
  33.  
  34.      An _a_d_d_r_e_s_s is either a decimal number that counts input
  35.      lines cumulatively across files, a `$' that addresses the
  36.      last line of input, or a context address, `/regular expres-
  37.      sion/', in the style of _e_d(1) modified thus:
  38.  
  39.           The escape sequence `\n' matches a newline embedded in
  40.           the pattern space.
  41.  
  42.      A command line with no addresses selects every pattern
  43.      space.
  44.  
  45.      A command line with one address selects each pattern space
  46.      that matches the address.
  47.  
  48.      A command line with two addresses selects the inclusive
  49.      range from the first pattern space that matches the first
  50.      address through the next pattern space that matches the
  51.      second.  (If the second address is a number less than or
  52.      equal to the line number first selected, only one line is
  53.      selected.) Thereafter the process is repeated, looking again
  54.      for the first address.
  55.  
  56.      Editing commands can be applied only to non-selected pattern
  57.      spaces by use of the negation function `!' (below).
  58.  
  59.      In the following list of functions the maximum number of
  60.  
  61.  
  62.  
  63. Sprite v1.0            September 30, 1987                       1
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. SED                       User Commands                       SED
  71.  
  72.  
  73.  
  74.      permissible addresses for each function is indicated in
  75.      parentheses.
  76.  
  77.      An argument denoted _t_e_x_t consists of one or more lines, all
  78.      but the last of which end with `\' to hide the newline.
  79.      Backslashes in text are treated like backslashes in the
  80.      replacement string of an `s' command, and may be used to
  81.      protect initial blanks and tabs against the stripping that
  82.      is done on every script line.
  83.  
  84.      An argument denoted _r_f_i_l_e or _w_f_i_l_e must terminate the com-
  85.      mand line and must be preceded by exactly one blank.  Each
  86.      _w_f_i_l_e is created before processing begins.  There can be at
  87.      most 10 distinct _w_f_i_l_e arguments.
  88.  
  89.      (1)a\
  90.      _t_e_x_t
  91.           Append.  Place _t_e_x_t on the output before reading the
  92.           next input line.
  93.  
  94.      (2)b _l_a_b_e_l
  95.           Branch to the `:' command bearing the _l_a_b_e_l.  If _l_a_b_e_l
  96.           is empty, branch to the end of the script.
  97.  
  98.      (2)c\
  99.      _t_e_x_t
  100.           Change.  Delete the pattern space.  With 0 or 1 address
  101.           or at the end of a 2-address range, place _t_e_x_t on the
  102.           output.  Start the next cycle.
  103.  
  104.      (2)d Delete the pattern space.  Start the next cycle.
  105.  
  106.      (2)D Delete the initial segment of the pattern space through
  107.           the first newline.  Start the next cycle.
  108.  
  109.      (2)g Replace the contents of the pattern space by the con-
  110.           tents of the hold space.
  111.  
  112.      (2)G Append the contents of the hold space to the pattern
  113.           space.
  114.  
  115.      (2)h Replace the contents of the hold space by the contents
  116.           of the pattern space.
  117.  
  118.      (2)H Append the contents of the pattern space to the hold
  119.           space.
  120.  
  121.      (1)i\
  122.      _t_e_x_t
  123.           Insert.  Place _t_e_x_t on the standard output.
  124.  
  125.      (2)n Copy the pattern space to the standard output.  Replace
  126.  
  127.  
  128.  
  129. Sprite v1.0            September 30, 1987                       2
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. SED                       User Commands                       SED
  137.  
  138.  
  139.  
  140.           the pattern space with the next line of input.
  141.  
  142.      (2)N Append the next line of input to the pattern space with
  143.           an embedded newline.  (The current line number
  144.           changes.)
  145.  
  146.      (2)p Print.  Copy the pattern space to the standard output.
  147.  
  148.      (2)P Copy the initial segment of the pattern space through
  149.           the first newline to the standard output.
  150.  
  151.      (1)q Quit.  Branch to the end of the script.  Do not start a
  152.           new cycle.
  153.  
  154.      (2)r _r_f_i_l_e
  155.           Read the contents of _r_f_i_l_e.  Place them on the output
  156.           before reading the next input line.
  157.  
  158.      (2)s/_r_e_g_u_l_a_r _e_x_p_r_e_s_s_i_o_n/_r_e_p_l_a_c_e_m_e_n_t/_f_l_a_g_s
  159.           Substitute the _r_e_p_l_a_c_e_m_e_n_t string for instances of the
  160.           _r_e_g_u_l_a_r _e_x_p_r_e_s_s_i_o_n in the pattern space.  Any character
  161.           may be used instead of `/'.  For a fuller description
  162.           see _e_d(1).  _F_l_a_g_s is zero or more of
  163.  
  164.           g    Global.  Substitute for all nonoverlapping
  165.                instances of the _r_e_g_u_l_a_r _e_x_p_r_e_s_s_i_o_n rather than
  166.                just the first one.
  167.  
  168.           p    Print the pattern space if a replacement was made.
  169.  
  170.           w _w_f_i_l_e
  171.                Write.  Append the pattern space to _w_f_i_l_e if a
  172.                replacement was made.
  173.  
  174.      (2)t _l_a_b_e_l
  175.           Test.  Branch to the `:' command bearing the _l_a_b_e_l if
  176.           any substitutions have been made since the most recent
  177.           reading of an input line or execution of a `t'.  If
  178.           _l_a_b_e_l is empty, branch to the end of the script.
  179.  
  180.      (2)w _w_f_i_l_e
  181.           Write.  Append the pattern space to _w_f_i_l_e.
  182.  
  183.      (2)x Exchange the contents of the pattern and hold spaces.
  184.  
  185.      (2)y/_s_t_r_i_n_g_1/_s_t_r_i_n_g_2/
  186.           Transform.  Replace all occurrences of characters in
  187.           _s_t_r_i_n_g_1 with the corresponding character in _s_t_r_i_n_g_2.
  188.           The lengths of _s_t_r_i_n_g_1 and _s_t_r_i_n_g_2 must be equal.
  189.  
  190.      (2)! _f_u_n_c_t_i_o_n
  191.           Don't.  Apply the _f_u_n_c_t_i_o_n (or group, if _f_u_n_c_t_i_o_n is
  192.  
  193.  
  194.  
  195. Sprite v1.0            September 30, 1987                       3
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202. SED                       User Commands                       SED
  203.  
  204.  
  205.  
  206.           `{') only to lines _n_o_t selected by the address(es).
  207.  
  208.      (0): _l_a_b_e_l
  209.           This command does nothing; it bears a _l_a_b_e_l for `b' and
  210.           `t' commands to branch to.
  211.  
  212.      (1)= Place the current line number on the standard output as
  213.           a line.
  214.  
  215.      (2){ Execute the following commands through a matching `}'
  216.           only when the pattern space is selected.
  217.  
  218.      (0)  An empty command is ignored.
  219.  
  220.      (0)# If a # appears as the first character on a line of a
  221.           script, then that entire line is treated as a comment,
  222.           with one exception.  If the first line of the script
  223.           starts with the characters ``#n'', then the default
  224.           output will be suppressed.  The rest of the line after
  225.           ``#n'' will also be ignored.  A script file must con-
  226.           tain at least one non-comment line.
  227.  
  228. SSEEEE AALLSSOO
  229.      ed(1), grep(1), awk(1), lex(1)
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261. Sprite v1.0            September 30, 1987                       4
  262.  
  263.  
  264.  
  265.